package priv.yiyuan.example.design.pay;

import priv.yiyuan.example.design.pay.wechat.LegacyWeChatPay;

import java.util.Map;

/**
 * 适配器类
 * <p>
 * 将 LegacyWeChatPay 适配道 PaymentProcessor 接口
 */
public class WeChatPayAdapter implements PaymentProcessor {

    /**
     * 原支付接口的引用
     */
    private LegacyWeChatPay legacyWeChatPay;

    public WeChatPayAdapter(LegacyWeChatPay legacyWeChatPay) {
        this.legacyWeChatPay = legacyWeChatPay;
    }

    @Override
    public boolean processPayment(double amount, Map<String, String> paymentDetails) {
        return legacyWeChatPay.pay(amount, paymentDetails.get("openId"));
    }

    @Override
    public boolean refund(double amount, String transactionId) {
        // 旧版本中，不支持退款，仅支持取消支付。
        return legacyWeChatPay.cancelPayment(transactionId);
    }
}
